package org.feng.controller;


import org.feng.common.MaskedMethod;
import org.feng.common.ResponseEntity;
import org.feng.dto.request.AddUserRequestDto;
import org.feng.dto.request.UpdateUserRequestDto;
import org.feng.service.IUserService;
import org.feng.vo.UserVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author fengjinsong
 * @since 2023-08-24
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private IUserService userService;

    @MaskedMethod
    @GetMapping("/list")
    public ResponseEntity<List<UserVO>> list() {
        return new ResponseEntity<>("查询用户数据成功", "200", userService.listUser());
    }

    @MaskedMethod
    @GetMapping("/listUserWithPermission")
    public ResponseEntity<List<UserVO>> listUserWithPermission() {
        return new ResponseEntity<>("查询用户数据成功", "200", userService.listUserWithPermission());
    }

    @MaskedMethod
    @GetMapping("/listUserWithRolePermission")
    public ResponseEntity<List<UserVO>> listUserWithRolePermission() {
        return new ResponseEntity<>("查询用户数据成功", "200", userService.listUserWithRolePermission());
    }

    @GetMapping("/selectOne/{username}")
    public ResponseEntity<UserVO> selectOneUserByName(@PathVariable("username") String username) {
        return new ResponseEntity<>("查询用户数据成功", "200", userService.selectOneUserByName(username));
    }

    @PutMapping("/add")
    public ResponseEntity<Integer> addUser(@RequestBody AddUserRequestDto addUserRequestDto) {
        return new ResponseEntity<>("新增用户数据成功", "200", userService.addUser(addUserRequestDto));
    }

    @PostMapping("/update")
    public ResponseEntity<UserVO> updateUser(@RequestBody @Validated UpdateUserRequestDto updateUserRequestDto) {
        return new ResponseEntity<>("更新用户数据成功", "200", userService.updateUser(updateUserRequestDto));
    }
}
